package com.wy.panda.common.sign;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.wy.panda.common.sign.handler.FormAndHeaderSignValidationHandler;
import com.wy.panda.common.sign.handler.FormAndParameterSignValidationHandler;
import com.wy.panda.common.sign.handler.JsonAndHeaderSignValidationHandler;
import com.wy.panda.common.sign.validator.MD5Validator;

/**
 * 签名验证相关配置
 * @author wangyuan
 * @since 2021年3月8日 下午11:49:22
 */
public class PandaSignConfig {

    /**
     * 签名验证处理器
     */
    private static final List<ISignValidationHandler> SIGN_VALIDATION_HANDLERS = new ArrayList<>();
    /**
     * 验证器MAP
     */
    private static final List<IValidator> VALIDATORS = new ArrayList<>();
    /**
     * app相关的key和secret
     */
    private static final Map<String, String> APP_MAP = new LinkedHashMap<>();
    
    static {
        registerValidator(new MD5Validator());
        
        registerSignValidationHandler(new FormAndHeaderSignValidationHandler());
        registerSignValidationHandler(new FormAndParameterSignValidationHandler());
        registerSignValidationHandler(new JsonAndHeaderSignValidationHandler());
    }
    
    public static void registerSignValidationHandler(ISignValidationHandler signValidationHandler) {
        SIGN_VALIDATION_HANDLERS.add(signValidationHandler);
    }
    
    public static void registerApp(String appKey, String appSecret) {
        APP_MAP.put(appKey, appSecret);
    }
    
    public static void registerValidator(IValidator validator) {
        VALIDATORS.add(validator);
    }
    
    public static List<ISignValidationHandler> signValidationHandler(){
        return SIGN_VALIDATION_HANDLERS;
    }
    
    public static List<IValidator> validator(){
        return VALIDATORS;
    }
    
    public static Map<String, String> appMap(){
        return APP_MAP;
    }
    
}
